package com.jing.weibo.service.pb;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jing.system.comm.enums.FansAttentionType;
import com.jing.system.model.PageCls;
import com.jing.weibo.mapper.pb.PbUserTypeSeatMapper;
import com.jing.weibo.pojo.fans.Fansattention;
import com.jing.weibo.pojo.pb.PbUserTypeSeat;
import com.jing.weibo.service.fans.FansAttentionService;

/**
 * 泡吧用户分区位置的Service
 * @author jing.yue
 * @version 2012/09/25 1.0.0
 */
@Component
public class PbUserTypeSeatService {

	@Autowired
	private PbUserTypeSeatMapper pbUserTypeSeatMapper;
	@Autowired
	private FansAttentionService fansAttentionService;

	/**
	 * 分页获取泡吧分区位置用户列表
	 * @param pbUserTypeSeat
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> findPbUserTypeSeat(PbUserTypeSeat pbUserTypeSeat) throws Exception {
		List<PbUserTypeSeat> pbUserTypeSeats = pbUserTypeSeatMapper.findPbUserTypeSeat(pbUserTypeSeat);
		//处理是否关注过了[查询我的关注信息中是否存在这个用户]
		Fansattention fansattention = new Fansattention();
		fansattention.setUsername(pbUserTypeSeat.getUsername());
		fansattention.setType(FansAttentionType.TYPE_ATTENTION.getCode());
		for (PbUserTypeSeat puts : pbUserTypeSeats) {
			fansattention.setFansattentionusername(puts.getUsername());
			if(fansAttentionService.findByUsernameFansnameType(fansattention) != null) {
				puts.setIsfa(1);
			} else {
				puts.setIsfa(0);
			}
		}
		Integer countSize = pbUserTypeSeatMapper.findPbUserTypeSeatCount(pbUserTypeSeat);
		PageCls pageCls = PageCls.setPageCls(pbUserTypeSeat.getPage(), pbUserTypeSeat.getSize(), null, null, countSize, pbUserTypeSeats.size(), pbUserTypeSeats);
		return pageCls.getPageInfo();
	}

	/**
	 * 保存泡吧用户分区位置
	 * @param pbUserTypeSeat
	 * @throws Exception
	 */
	public void savePbUserTypeSeat(PbUserTypeSeat pbUserTypeSeat) throws Exception {
		pbUserTypeSeatMapper.savePbUserTypeSeat(pbUserTypeSeat);
	}

	/**
	 * 根据用户名和位置ID修改非当前用户的信息为删除状态
	 * @param pbUserTypeSeat
	 * @throws Exception
	 */
	public void updatePbUserTypeSeatToLog(PbUserTypeSeat pbUserTypeSeat) throws Exception {
		pbUserTypeSeatMapper.updatePbUserTypeSeatToLog(pbUserTypeSeat);
	}

	/**
	 * 根据用户名修改当前用户的所有位置信息为删除状态
	 * @param pbUserTypeSeat
	 * @throws Exception
	 */
	public void updatePbUserTypeSeatUsernameToLog(PbUserTypeSeat pbUserTypeSeat) throws Exception {
		pbUserTypeSeatMapper.updatePbUserTypeSeatUsernameToLog(pbUserTypeSeat);
	}

	/**
	 * 根据ID查询对象
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public PbUserTypeSeat findByIdPbUserTypeSeat(Integer id) throws Exception {
		return pbUserTypeSeatMapper.findByIdPbUserTypeSeat(id);
	}

	/**
	 * 根据ID修改粉丝数目
	 * @param pbUserTypeSeat
	 * @throws Exception
	 */
	public void updatePbUserTypeSeatFansnum(PbUserTypeSeat pbUserTypeSeat) throws Exception {
		pbUserTypeSeatMapper.updatePbUserTypeSeatFansnum(pbUserTypeSeat);
	}

	/**
	 * 修改用户分区位置信息
	 * @param pbUserTypeSeat
	 * @throws Exception
	 */
	public void updatePbUserTypeSeat(PbUserTypeSeat pbUserTypeSeat) throws Exception {
		pbUserTypeSeatMapper.updatePbUserTypeSeat(pbUserTypeSeat);
	}

	/**
	 * 分页根据用户名获取用户泡吧分区位置列表信息
	 * @param pbUserTypeSeat
	 * @return
	 * @throws Exception
	 */
	public Map<String, Object> findByUsernamePuts(PbUserTypeSeat pbUserTypeSeat) throws Exception {
		List<PbUserTypeSeat> pbUserTypeSeats = pbUserTypeSeatMapper.findByUsernamePuts(pbUserTypeSeat);
		Integer countSize = pbUserTypeSeatMapper.findByUsernamePutsCount(pbUserTypeSeat);
		PageCls pageCls = PageCls.setPageCls(pbUserTypeSeat.getPage(), pbUserTypeSeat.getSize(), null, null, countSize, pbUserTypeSeats.size(), pbUserTypeSeats);
		return pageCls.getPageInfo();
	}

	/**
	 * 根据用户名和泡吧分区ID获取第一个用户泡吧分区位置对象
	 * @param pbUserTypeSeat
	 * @return
	 * @throws Exception
	 */
	public PbUserTypeSeat findByUsernameTypeidPuts(PbUserTypeSeat pbUserTypeSeat) throws Exception {
		return pbUserTypeSeatMapper.findByUsernameTypeidPuts(pbUserTypeSeat);
	}

	/**
	 * 根据用户名和ID修改当前位置为删除状态
	 * @param pbUserTypeSeat
	 * @throws Exception
	 */
	public void updatePbUserTypeSeatUsernameIdToLog(PbUserTypeSeat pbUserTypeSeat) throws Exception {
		pbUserTypeSeatMapper.updatePbUserTypeSeatUsernameIdToLog(pbUserTypeSeat);
	}
}
